import pygame

class CSoundManager(object):
    """ Loads, Retreives and Releases Sounds. """
    
    mSounds = {}
        
    @staticmethod    
    def LoadSound( filename , name ):
        """ Load our sound with a filename and give it a unique reference name. Return a handle to its instance or None. """
        
        # Return null if sound key already exists.
        if( name in CSoundManager.mSounds ):
            return None
        
        # Load in our sound with alpha then return it
        CSoundManager.mSounds[ name ] = pygame.mixer.Sound( filename )
        CSoundManager.mSounds[ name ].set_volume(0.25)
        return CSoundManager.mSounds[ name ]
    
    @staticmethod
    def GetSound( name ):
        """ Get a sound from its name. """
        if( name in CSoundManager.mSounds ):
            return CSoundManager.mSounds[name]
        else:
            return None
        
    @staticmethod
    def FreeSound( name ):
        """ Remove a sound from the manager. """
        
        # Kill reference for GC & Delete Dictionary entry
        CSoundManager[name] = None
        del CSoundManager[name]
        
    @staticmethod
    def IsLoadedSound( name ):
        """ Get whether or not a sound has been loaded. """
        if( name in CSoundManager.mSounds):
            return True
        else:
            return False
        
    @staticmethod
    def FreeAllsounds():
        """ Free all sounds. """
        
        for k in CSoundManager.mSounds.keys():
            CSoundManager.mSounds[k] = None
            del CSoundManager.mSounds[k]
            
        
    
        
        
        
         

